//
//  UIImageView+WebImage.swift
//  Weibo
//
//  Created by kobe on 2016/12/26.
//  Copyright © 2016年 kobe. All rights reserved.
//

import SDWebImage

extension UIImageView {
    
    //包装sdwebimage
    func cz_setImage(urlStr:String?,placeholderImage:UIImage?,isAvatar:Bool = false) {
        
        guard let urlStr = urlStr,let url = URL(string: urlStr) else {
            
            image = placeholderImage
            
            return
        }
        
        
        sd_setImage(with: url, placeholderImage:placeholderImage, options: [], progress: nil) { [weak self](image, _, _, _) in
            
            // 完成回调 - 对头像进行判断
            if isAvatar {
                self?.image = image?.cz_avaterImage(size: self?.bounds.size)
            }
            
        }
        
        
        
        
    }
}
